package fair.controller;

import fair.entity.Result;
import fair.utils.PoiUtils;
import fair.utils.SimHashUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author: Jingtao_Wu
 * @DATE: 2021-03-04 13:28
 **/
@Api(tags = "文档管理")
@RestController
@RequestMapping(value = "/check", produces = MediaType.APPLICATION_JSON_VALUE)
public class CheckController {

    /**
     * 按段落解析一个word文档
     * @param files
     * @return
     * @throws Exception
     */
    @ApiOperation(value="对作业进行批量查重", notes="解析word文档提取字符串，用SimHash算法进行文本比较")
    @RequestMapping(value = "upload", method = RequestMethod.POST)
    public Result uploadFile(@RequestParam(value = "files", required = true) MultipartFile[] files){
        try {
            String[] words = new String[files.length];
            for (int i = 0; i < files.length; i++) {
                words[i] = PoiUtils.readWordString(files[i]);
            }
            SimHashUtil simHash1 = new SimHashUtil(words[0], 64);
            SimHashUtil simHash2 = new SimHashUtil(words[1], 64);
            double semblance = simHash1.getSemblance(simHash2);

            return new Result(0, "", words);
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(500, "内部异常");
        }
    }


//    public Result findResult()

}
